package com.idol.factory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className BeanContainer
 * @description Bean容器
 * @date 2020/10/13 14:05
 **/
public class BeanContainer {
    private Map<String, Object> container = new HashMap<>();
    private Map<String, String> idClassMap = new HashMap<>();
    private static final BeanContainer beanContainer = new BeanContainer();

    private BeanContainer() {
    }

    public static BeanContainer getBeanContainer() {
        return beanContainer;
    }


    public void put(String id, String clazz, Object instance) {
        container.put(clazz, instance);
        idClassMap.put(id, clazz);
    }

    public void put(String clazz, Object instance) {
        container.put(clazz, instance);
    }

    public Object get(String key) {
        Object result = container.get(key);
        if (result == null) {
            result = container.get(idClassMap.get(key));
        }
        return result;
    }

    public int size() {
        return container.size();
    }

    public void remove(String key) {
        container.remove(key);
    }

}
